package com.wzq.design.business.base.dept.controller;

import com.wzq.design.base.controller.CommController;
import com.wzq.design.base.dto.QueryByIdRequest;
import com.wzq.design.business.base.dept.dto.BaseDeptDto;
import com.wzq.design.business.base.dept.dto.BaseDeptTreeDto;
import com.wzq.design.business.base.dept.service.BaseDeptService;
import com.wzq.ssm.parent.base.dto.JsonResult;
import com.wzq.design.base.dto.RemoveRequest;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (BaseDept)表控制层
 *
 * @author wangzhiqiang
 * @since 2023-06-20 11:02:08
 */
@RestController
@RequestMapping("base/dept")
public class BaseDeptController extends CommController {
    /**
     * 服务对象
     */
    private final BaseDeptService baseDeptService;

    public BaseDeptController(BaseDeptService baseDeptService) {
        this.baseDeptService = baseDeptService;
    }


    @GetMapping("/listTree")
    public JsonResult<List<BaseDeptTreeDto>> listTree() {
        return JsonResult.success("查询成功", baseDeptService.listTree());
    }


    @PostMapping("/delete")
    public JsonResult<?> delete(@RequestBody RemoveRequest request) {
        baseDeptService.deleteByIds(request.getIds());
        return JsonResult.success("删除成功");
    }

    @PostMapping("/save")
    public JsonResult<?> save(@RequestBody BaseDeptDto request) {
        return JsonResult.success("保存成功", baseDeptService.save(request));
    }

    @GetMapping("/findById")
    public JsonResult<BaseDeptDto> findById(QueryByIdRequest request) {
        return JsonResult.success("保存成功", baseDeptService.findById(request.getId()));
    }
}

